import 'package:flutter/material.dart';
import '../common.dart';

class MallIntegral extends StatefulWidget {
  const MallIntegral({super.key});
  @override
  State<MallIntegral> createState() => _HomePageState();
}

class _HomePageState extends State<MallIntegral>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  List deliveryList = [];

  getInfo(type) {
    getData(
      url: '/third/delivery',
      data: {'page': "1", "per_page": '200', 'type': type},
    ).then((res) {
      if (res != null) {
        deliveryList = res;
        setState(() {});
      }
    });
  }

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 2, vsync: this);
    WidgetsBinding.instance.addPostFrameCallback((_) {
      getInfo('1');
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color(0XFFFFFFFF),
        centerTitle: true,
        title: wText(text: '兑换明细', size: 18),
        leading: buildBackButton(context),
        bottom: TabBar(
          indicatorColor: Color(0XFF0F172B),
          indicatorWeight: 3.0,
          dividerColor: Color(0XFFF8F9FD),
          labelColor: Color(0XFF0F172B),
          labelPadding: EdgeInsets.symmetric(vertical: 5),
          unselectedLabelColor: Color(0xff999999),
          dividerHeight: 3,
          indicatorSize: TabBarIndicatorSize.tab,
          controller: _tabController,
          onTap: (index) {
            deliveryList = [];

            if (index == 1) {
              getInfo('2');
            } else {
              getInfo('1');
            }
          },
          tabs: [
            Text('已提货', style: TextStyle(fontSize: 14)),
            Text('已发货', style: TextStyle(fontSize: 14)),
          ],
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: [
          ListView(
            padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
            children: [
              if (deliveryList.isEmpty) isdata(),

              for (var item in deliveryList.asMap().entries)
                Container(
                  margin: EdgeInsets.only(top: 15),
                  padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
                  decoration: BoxDecoration(
                    color: Color(0XFFF8F9FD),
                    borderRadius: BorderRadius.circular(10),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      Container(
                        width: 130,
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            wText(text: '消耗藏品', color: '878b95'),
                            SizedBox(height: 5),
                            wImage(
                              url: '${item.value['form_thumb']}',
                              width: 130,
                              height: 130,
                              borderRadius: 10,
                            ),
                            SizedBox(height: 5),

                            wText(text: '${item.value['form_title']}'),
                          ],
                        ),
                      ),
                      wImage(url: 'youbian', width: 35),
                      Container(
                        width: 130,
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            wText(text: '兑换商品', color: '878b95'),
                            SizedBox(height: 5),
                            wImage(
                              url: '${item.value['to_thumb']}',
                              width: 130,
                              height: 130,
                              borderRadius: 10,
                            ),
                            SizedBox(height: 5),

                            wText(text: '${item.value['to_title']}'),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
            ],
          ),
          ListView(
            padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
            children: [
              if (deliveryList.isEmpty) isdata(),
              for (var item in deliveryList.asMap().entries)
                Container(
                  margin: EdgeInsets.only(top: 15),
                  padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
                  decoration: BoxDecoration(
                    color: Color(0XFFF8F9FD),
                    borderRadius: BorderRadius.circular(10),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      Container(
                        width: 130,
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            wText(text: '消耗藏品', color: '878b95'),
                            SizedBox(height: 5),
                            wImage(
                              url: '${item.value['form_thumb']}',
                              width: 130,
                              height: 130,
                              borderRadius: 10,
                            ),
                            SizedBox(height: 5),

                            wText(text: '${item.value['form_title']}'),
                            SizedBox(height: 45),
                          ],
                        ),
                      ),
                      wImage(url: 'youbian', width: 35),
                      Container(
                        width: 130,
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            wText(text: '兑换商品', color: '878b95'),
                            SizedBox(height: 5),
                            wImage(
                              url: '${item.value['to_thumb']}',
                              width: 130,
                              height: 130,
                              borderRadius: 10,
                            ),
                            SizedBox(height: 5),

                            wText(text: '${item.value['to_title']}'),
                            SizedBox(height: 15),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                GestureDetector(
                                  onTap: () {
                                    wTan(
                                      text: Column(
                                        children: [
                                          Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.center,
                                            children: [
                                              SizedBox(width: 20),

                                              wText(
                                                text: '快递公司',
                                                size: 16,
                                                color: '878B95',
                                              ),
                                              SizedBox(width: 20),
                                              Expanded(
                                                child: wText(
                                                  text:
                                                      '${item.value['delivery_name']}',
                                                  size: 16,
                                                  color: '0F172B',
                                                ),
                                              ),
                                            ],
                                          ),
                                          SizedBox(height: 15),
                                          Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.center,
                                            children: [
                                              SizedBox(width: 20),

                                              wText(
                                                text: '物流单号',
                                                size: 16,
                                                color: '878B95',
                                              ),
                                              SizedBox(width: 20),
                                              Expanded(
                                                child: GestureDetector(
                                                  onTap: () {
                                                    copy(
                                                      context,
                                                      '${item.value['delivery_no']}',
                                                    );
                                                  },
                                                  child: Row(
                                                    children: [
                                                      wText(
                                                        text:
                                                            '${item.value['delivery_no']}',
                                                        size: 16,
                                                        color: '0F172B',
                                                      ),
                                                      wImage(
                                                        url: 'copy',
                                                        width: 15,
                                                      ),
                                                    ],
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ],
                                      ),
                                      click: () async {
                                        back();
                                      },
                                    );
                                  },
                                  child: Container(
                                    alignment: Alignment.center,
                                    width: 70,
                                    height: 30,
                                    decoration: BoxDecoration(
                                      color: Color(0XFF0F172B),
                                      borderRadius: BorderRadius.circular(20),
                                    ),
                                    child: wText(text: '物流信息', color: 'FFFFFF'),
                                  ),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
            ],
          ),
        ],
      ),
    );
  }
}
